
import LayerInfo from "./LayerInfo"
import BaseView from "../base/view/BaseView";
export default abstract class LayerManager {

    protected root: cc.Node;
    protected list: Array<LayerInfo>;
    init(node: cc.Node):void{
        this.root = node;
        this.list = new Array<LayerInfo>();
    }

    count() {
        return this.list.length;
    }

    has(layer:LayerInfo){
        for (let index = 0; index < this.list.length; index++) {
            const element = this.list[index];
            if(layer === element){
                return true;
            }
        }
        return false;
    }

    //添加layer
    abstract pushView(layer:LayerInfo);

    // 移除layer
    abstract popView(view:BaseView):boolean;

    //删除指定位置的layer
    removeView(layer:BaseView):boolean{
        for (let index = 0; index < this.list.length; index++) {
            const element = this.list[index];
            if(layer === element.getLayer()){
                element.destroy();
                this.list.splice(index,1);
                return true;
            }
        }
        return false;
    }

    clear(){
        // this.root.removeAllChildren(true);
    }

}
